package profilesettings.data;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class AboutMeTests implements Runable_Interface {

	private int startSize;

	@Override
	public void run(ArrayList<String> codeInjection, int codeInjectionSize) {
		ArrayList<String> webElements = new ArrayList<String>();
		webElements.add("email");
		webElements.add("password");
		webElements.add("(//a[contains(@href, '')])[15]");
		webElements.add("//textarea");
		webElements.add("//div[28]/div/div[2]/form/div[2]/div[2]/div/input");
		
		testsAboutMe(webElements, codeInjection, codeInjectionSize);
	}

	private void testsAboutMe(ArrayList<String> webElements,
			ArrayList<String> codeInjection, int codeInjectionSize) {
		for(startSize = 1; startSize < codeInjectionSize; startSize++){
			WebDriver driver = new FirefoxDriver();
			driver.get("https://snapsation.com/login");
			WebElement email = driver.findElement(By.name(webElements.get(0)));
			email.sendKeys("damciodamcio666@gmail.com");
			WebElement password = driver.findElement(By.name(webElements.get(1)));
			password.sendKeys("admin123admin");
			email.submit();
			driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); 
			driver.get("https://www.snapsation.com/settings/");
			WebElement aboutMe = driver.findElement(By.xpath(webElements.get(2)));
			aboutMe.click();
			WebElement aboutMeTextArea = driver.findElement(By.xpath(webElements.get(3)));
			aboutMeTextArea.sendKeys(codeInjection.get(startSize));
			WebElement aboutMeSubmit = driver.findElement(By.xpath(webElements.get(4)));
			aboutMeSubmit.click();
			try {
				Thread.sleep(1800);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

}
